package com.wl156.activities.publish;

import org.ksoap2.serialization.SoapObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;

import com.wl156.lite.R;
import com.wl156.activities.HomeActivity;
import com.wl156.activities.find.CarMessageInfo;
import com.wl156.activities.find.GoodInfo;
import com.wl156.adapters.GoodAdapter;
import com.wl156.adapters.TruckAdapter;
import com.wl156.adapters.TruckMessageAdapter;
import com.wl156.model.WebServiceClient.OnWebServiceCompleteListener;

public class NewCarInfoAfter extends NewInfoAfterBase {

	private GoodAdapter mAdapter;

	String startLocationLv1 = "";
	String startLocationLv2 = "";
	String startLocationLv3 = "";
	String endLocationLv1 = "";
	String endLocationLv2 = "";
	String endLocationLv3;
	String setOffDate = "";
	String comment = "";
	String freightName = "";
	String freightTonnage = "";
	String freightTonnageSymbol = "";
	String freightTruckLengthRequired = "";
	String freightTruckLengthRequiredSymbol = "";
	String setOffDateSymbol = "";
	
	protected Class getGoodOrCarInfoClass() {
		return GoodInfo.class;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mHeaderStub.setLayoutResource(R.layout.item_good_header);
		mHeaderStub.inflate();
		mTipView.setText("以下显示最符合匹配的十个货物");

		Bundle extras = getIntent().getExtras();
		startLocationLv1 = extras.getString("startLocationLv1");
		startLocationLv2 = extras.getString("startLocationLv2");
		endLocationLv1 = extras.getString("endLocationLv1");
		// startLocationLv3 = extras.getString("startLocationLv3");
		// endLocationLv1 = extras.getString("endLocationLv1");
		// endLocationLv2 = extras.getString("endLocationLv2");
		// endLocationLv3 = extras.getString("endLocationLv3");
		// setOffDate = extras.getString("date");
		// comment = extras.getString("comment");
		freightName = "";
		freightTonnage = "";
		freightTonnageSymbol = "";
		freightTruckLengthRequired = "";
		freightTruckLengthRequiredSymbol = "";
		setOffDateSymbol = "";

		mWebServiceClient.commonFindFreightMessageAsync(mCertificate,
				startLocationLv1, startLocationLv2, startLocationLv3,
				endLocationLv1, endLocationLv2, endLocationLv3, freightName,
				freightTonnage, freightTonnageSymbol,
				freightTruckLengthRequired, freightTruckLengthRequiredSymbol,
				setOffDate, setOffDateSymbol, 0, 10,
				mOnWebServiceCompleteListener);
	}

	OnWebServiceCompleteListener mOnWebServiceCompleteListener = new OnWebServiceCompleteListener() {
		@Override
		public void onPostExecute(Object result) {
			if (result instanceof SoapObject) {
				SoapObject so = (SoapObject) result;
				if (so.getPropertyCount() == 0) {
				} else if (so.getPropertyCount() == 1
						&& ((SoapObject) so.getProperty(0)).getPropertyCount() == 0) {
					SoapObject so1 = (SoapObject) so.getProperty(0);
					if (so1.getPropertyCount() == 0) {
					}
				} else {
					mAdapter = new GoodAdapter(NewCarInfoAfter.this, so);
					mListView.setAdapter(mAdapter);
				}
			} else {
				AlertDialog.Builder builder = new Builder(NewCarInfoAfter.this);
				builder.setMessage("网络请求超时！");
				builder.setPositiveButton("重试",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								mWebServiceClient
										.commonFindFreightMessageAsync(
												mCertificate,
												startLocationLv1,
												startLocationLv2,
												startLocationLv3,
												endLocationLv1,
												endLocationLv2,
												endLocationLv3,
												freightName,
												freightTonnage,
												freightTonnageSymbol,
												freightTruckLengthRequired,
												freightTruckLengthRequiredSymbol,
												setOffDate, setOffDateSymbol,
												1, 10,
												mOnWebServiceCompleteListener);
							}
						});
				builder.setNegativeButton("取消",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								finish();
							}
						});
				builder.show();
			}
		}
	};
}
